-- Decompiled with the Synapse X Luau decompiler.
local server = _G.server;
local ServerOHOH = _G.ServerOHOH;
local CommonOHOH = _G.CommonOHOH;
local ConnectClass=CommonOHOH.load.Connect();

local M = ServerOHOH.class.new(script, ServerOHOH.files.CharacterObject());

local ColliderGroup = ServerOHOH.load.ColliderGroup();
local ColliderManager = ServerOHOH.load.ColliderManager();
local game_cfg = ServerOHOH.config.Game
local gWalkSpeed=game_cfg.WalkSpeed

function M.new(self, character)
	return M(self, character);
end;

function M.ctor(self, character, player)
	M.super.ctor(self, character);

	self.player = player;
	ColliderManager:SetAllGroup(self.main_inst, ColliderGroup.character);
	self:GetHumanoid().WalkSpeed=gWalkSpeed

end;

function M.dtor(self)
	M.super.dtor(self);
end;


local PlayerCharacterHelper = _G.CommonOHOH.load.PlayerCharacterHelper();
BecomeUserId=nil

function M.ChangeCharacterByOBJ(self,obj)
	if obj then
		local CF= self:GetCFrame()
		self.player.main_inst:LoadCharacter()
		self.player.main_inst.Character=obj
		self.player.main_inst.Character.Parent = workspace
		self.main_inst=obj
		obj:SetPrimaryPartCFrame(CF)
	else
		self.player.main_inst:LoadCharacter()
	end

end
function M.ChangeCharacter(self,userId)

	if BecomeUserId==userId then
		BecomeUserId=nil
		self:ChangeCharacterByOBJ(nil)
	else
		BecomeUserId=userId
		PlayerCharacterHelper.GetPlayerCharacter(userId,function(obj)
			assert(obj,"CreateFriend obj=null")
			self:ChangeCharacterByOBJ(obj)
		end)
	end
end

function M.OnDead(self)
	task.wait(1)
	self.player.main_inst:LoadCharacter()
end;

return M;
